<template>
  <!-- 有子数据的表示为菜单栏 -->
  <template v-if="dataOption.list && dataOption.list.length > 0">
    <el-sub-menu :index="`${dataOption.id}`">
      <template #title>
        <div class="page-icon">
          <img :src="dataOption.icon" />
        </div>
        <span class="page-title">{{ dataOption.title }}</span>
      </template>
      <app-menu-item v-for="item in dataOption.list" :data-option="item"></app-menu-item>
    </el-sub-menu>
  </template>
  <!-- 五子数据,表示为可点击进入的菜单 -->
  <template v-else>
    <el-menu-item :index="`${dataOption.id}`" style="padding:0 30px">
      <!-- 选中 -->
      <template v-if="isSelectMenuItem">
        <div class="page-item">
          <div class="page-itembtn">
            <div class="page-icon">
              <img :src="dataOption.icon" />
            </div>
            <div class="page-title">{{ dataOption.title }}</div>
          </div>
        </div>
      </template>
      <!-- 未选中 -->
      <template v-else>
        <div class="page-item">
          <div class="page-icon">
            <img :src="dataOption.icon" />
          </div>
          <div class="page-title">{{ dataOption.title }}</div>
        </div>
      </template>

    </el-menu-item>
  </template>
</template>

<script lang="ts">
import { defineComponent, reactive, ref, computed } from "vue";

export default defineComponent({
  name: "AppMenuItem",
})
</script>

<script setup lang="ts">
import { withDefaults } from "vue";
import { MenuNodeClass } from "@/model/AppModel";
import { selectTabItem } from "@/store/tabs";

let props = withDefaults(defineProps<{
  dataOption: MenuNodeClass
}>(), {

})

/**
 * 当前menu是否被选中
 */
let isSelectMenuItem = computed(() => {
  return selectTabItem.value ? selectTabItem.value.id == props.dataOption.tabId : false
})

</script>

<style lang="less" scoped>
@import url("../../config.less");

.page-item {
  display: flex;
  width: 100%;
  // justify-content: center;
  align-items: center;
}

.page-itembtn {
  margin-left:-10px;
  width: calc(100% + 20px);
  display: flex;
  align-items: center;
  padding-left: 10px;
  // justify-content:center;
  background-color: var(--primaryColor);
  color:white;
  // background-color: white;
  border-radius: 5px;
  height: 40px;
  // filter: drop-shadow(0 5px 5px var(--primaryColor50));
  filter: drop-shadow(0 5px 5px rgba(0,0,0,0.1));
}

.page-icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  display: flex;
  justify-content: center;
  color: white;
  font-weight: bold;
  // border-right: 1px solid rgba(255, 255, 255, 0.1);
  align-items: center;
  font-size: 16px;

  // border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  >img {
    display: block;
    width: 100%;
    height: 100%;
  }
}

.page-title {
  margin-left: 8px;
  font-size: 13px;
  line-height: 15px;
  padding-top:3px;
}
</style>
